package observer;

import lombok.Getter;

/**
 * 核心类
 * 1.包含最新的天气情况信息
 * 2.含有CurrentConditions对象
 * 3.当数据有更新时，就主动的调用CurrentConditions对象update方法(含 display), 这样他们（接入方）就看到最新的信息
 */
public class WeatherData {
    private CurrentConditions currentConditions;
    @Getter
    private float temperature;
    @Getter
    private float pressure;
    @Getter
    private float humidity;

    public WeatherData(CurrentConditions currentConditions) {
        this.currentConditions = currentConditions;
    }

    public void setData(float temperature, float pressure, float humidity) {
        this.temperature = temperature;
        this.pressure = pressure;
        this.humidity = humidity;
        // 推送给接入者
        pushData();
    }

    // 推送给接入者
    private void pushData() {
        currentConditions.update(getTemperature(), getPressure(), getHumidity());
    }

}
